package com.app.constant

import com.fasterxml.jackson.annotation.JsonFormat
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
/**
 * 符号常量枚举
 * Created by three on 14-8-4.
 * User; three
 */
@CompileStatic
@TypeChecked
class CommonConstant {

    /**
     * 是否可用
     */
    public enum IsActive implements IEnum<IsActive, Boolean, String>{
        TRUE(true, "可用"),
        FALSE(false, "不可用")

        boolean value;
        String desc;

        IsActive(Boolean value, String desc) {
            this.value = value;
            this.desc = desc;
        }

        @Override
        String getDesc() {
            return this.desc;
        }

        @Override
        Boolean getValue() {
            return this.value
        }

        @Override
        String parse(Boolean value) {
            for(IsActive isActive: IsActive.values()){
                if(isActive.value == (value as Boolean)){
                    return isActive.desc
                }
            }

            return "没有对应的枚举值"
        }

        @Override
        IsActive parseT(Boolean value) {
            for(IsActive isActive: IsActive.values()){
                if(isActive.value == (value as Boolean)){
                    return isActive
                }
            }

            return null;
        }
    };

    @JsonFormat(shape= JsonFormat.Shape.OBJECT)
    public enum FunctionPosition implements IEnum<FunctionPosition, Integer, String> {
        LEFT(0, "左边菜单"),
        LIST_TOP(1, "列表顶部菜单"),
        LIST_ROW(2, "列表行菜单")


        private String desc;
        private int value;

        FunctionPosition(int val, String desc) {
            this.value = val;
            this.desc = desc;
        }
        @Override
        String getDesc() {
            return this.desc;
        }

        @Override
        Integer getValue() {
            return this.value;
        }

        @Override
        String parse(Integer value) {
            for(FunctionPosition pos: FunctionPosition.values()){
                if(pos.value == value){
                    return pos.desc
                }
            }

            return "位置错误"
        }

        @Override
        FunctionPosition parseT(Integer value) {
            for(FunctionPosition pos: FunctionPosition.values()){
                if(pos.value == value){
                    return pos;
                }
            }

            return null;
        }
    }

    public enum FlagsConstant implements IEnum<FlagsConstant, String, String> {

        SESSION_USER_KEY("session_user_key", "session中保存当前用户的使用的关键字")

        String value;
        String desc;

        FlagsConstant(String value, String desc) {
            this.value = value;
            this.desc = desc;
        }

        @Override
        String getDesc() {
            return this.desc
        }

        @Override
        String getValue() {
            return this.value;
        }

        @Override
        String parse(String value) {
            for(FlagsConstant enumV: FlagsConstant.values()){
                if(enumV.value == (value as String)){
                    return enumV.desc
                }
            }

            return "没有对应的枚举值"
        }

        @Override
        FlagsConstant parseT(String value) {
            for(FlagsConstant enumV: FlagsConstant.values()){
                if(enumV.value == (value as String)){
                    return enumV
                }
            }

            return null
        }

    }
}
